Skip to content

test(rivetkit-core): move private tests to crate root#4792

Open
NathanFlurry wants to merge 1 commit into04-24-replay/runner-config-protocol-version-testfrom
04-24-replay/rivetkit-core-private-test-layout
Open

test(rivetkit-core): move private tests to crate root#4792
NathanFlurry wants to merge 1 commit into04-24-replay/runner-config-protocol-version-testfrom
04-24-replay/rivetkit-core-private-test-layout

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 27, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 27, 2026

PR #4792 Review: Move private tests to crate root

Overview

Migrates test modules from inline #[cfg(test)] mod tests { ... } blocks in source files (or tests/modules/) to flat files under tests/ at the crate root. Because these tests need access to private items, autotests = false prevents Cargo from compiling the tests/*.rs files as standalone integration test binaries; they remain included via #[path] shims in each source file. The PR also centralizes test_inspector_env_lock() into src/inspector/auth.rs and fixes a test assertion in task.rs.

This directly implements the CLAUDE.md requirement: "Rust tests live under tests/, not inline #[cfg(test)] mod tests in src/."


What's Good

  • CLAUDE.md compliance: All inline test blocks are now in tests/, matching the codebase convention.
  • autotests = false is correct: Without it, Cargo would try to compile the #[path]-included files as standalone integration test binaries and fail on use super::*;. The setting is a necessary consequence of the design.
  • Centralized test_inspector_env_lock(): Previously a static INSPECTOR_ENV_LOCK local to tests/modules/inspector.rs, it is now a shared OnceLock<Mutex<()>> in src/inspector/auth.rs. After flattening, inspector auth tests can land in different test binaries; the shared lock ensures proper env-var serialization across all tests touching _RIVET_TEST_INSPECTOR_TOKEN.
  • Test assertion fix in task.rs: Correcting the assertion from 0 to 1 test_batch_get_call_count() (with a clarifying comment) and renaming the test to _without_startup_bundle_batch_get improves accuracy.
  • Consistent shim pattern: Every source file uses the same #[path = "../../tests/X.rs"] shim with an explanatory comment.

Issues

1. autotests = false has no explanation in Cargo.toml (minor)

The setting is non-obvious. A future contributor adding a standalone integration test would be surprised it is silently ignored. A comment prevents this:

# Tests in tests/ are included via #[path] shims in source files for private-item access.
# They are not standalone integration test binaries, so autotests must stay false.
autotests = false

2. test_inspector_env_lock() uses std::sync::Mutex instead of parking_lot::Mutex (minor)

CLAUDE.md says test-only global serialization should use parking_lot. Even though the function is #[cfg(test)], it lives in a production source file, and the codebase consistently uses parking_lot for forced-sync contexts:

#[cfg(test)] use parking_lot::Mutex;
#[cfg(test)] use std::sync::OnceLock;

#[cfg(test)]
pub(crate) fn test_inspector_env_lock() -> &'static Mutex<()> {
    static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
    LOCK.get_or_init(|| Mutex::new(()))
}

3. mod moved_tests is inconsistently applied and transitionally named (minor)

Some files wrap tests in mod moved_tests { ... } (inspector.rs, registry_http.rs, serverless.rs, task.rs, work_registry.rs) while others do not. The name describes migration history rather than module purpose. Post-migration these wrappers add no value; either remove them or rename to something semantically meaningful.

4. Substantive test fix bundled into a mechanical refactor (low risk, worth noting)

The task.rs change corrects the expected batch-get count from 0 to 1 and adds an env guard. This is a genuine correctness fix (the old assertion was wrong; the test was previously flaky when _RIVET_TEST_INSPECTOR_TOKEN was set by a preceding test). Good change, but non-trivial inside an otherwise purely structural refactor.


Summary

The approach is sound and the CLAUDE.md requirement is satisfied. The two actionable items are the missing Cargo.toml comment and the std::sync::Mutex to parking_lot::Mutex swap in the test helper. The rest are nits.

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4792

All packages published as 0.0.0-pr.4792.8c20f1a with tag pr-4792.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-8c20f1a
docker pull rivetdev/engine:full-8c20f1a
Individual packages
npm install rivetkit@pr-4792
npm install @rivetkit/react@pr-4792
npm install @rivetkit/rivetkit-napi@pr-4792
npm install @rivetkit/workflow-engine@pr-4792

@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from e113941 to 448a22d Compare April 27, 2026 03:27
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from 55071a7 to 2408188 Compare April 27, 2026 03:27
@NathanFlurry NathanFlurry marked this pull request as ready for review April 27, 2026 03:53
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 448a22d to f691ba2 Compare April 27, 2026 03:59
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch 2 times, most recently from 0b216fc to d66a0b9 Compare April 27, 2026 04:35
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch 2 times, most recently from 2ba33ef to da8c2af Compare April 27, 2026 05:01
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from d66a0b9 to 5b530d1 Compare April 27, 2026 05:37
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from da8c2af to 6fdd701 Compare April 27, 2026 05:37
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from 5b530d1 to d4ab11d Compare April 27, 2026 07:30
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 6fdd701 to c23eb1d Compare April 27, 2026 07:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from d4ab11d to e975b91 Compare April 27, 2026 07:57
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from c23eb1d to 81d507e Compare April 27, 2026 07:57
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from e975b91 to 9648497 Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 81d507e to 752dc10 Compare April 27, 2026 08:31
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 752dc10 to 3acdfe8 Compare April 27, 2026 17:35
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/runner-config-protocol-version-test branch from 0939a5c to 4514b8b Compare April 27, 2026 19:06
@NathanFlurry NathanFlurry force-pushed the 04-24-replay/rivetkit-core-private-test-layout branch from 3acdfe8 to 3cb32e3 Compare April 27, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant